//package com.user.config;
//
//import com.common.entity.user.TbUser;
//import com.user.service.UserService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.authority.AuthorityUtils;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.stereotype.Service;
//
////@Service
//public class UserDetailServiceImpl implements UserDetailsService {
//
//    @Autowired
//    private UserService userService;
//
//    @Autowired
//    private PasswordEncoder passwordEncoder;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        System.out.println("执行自定义登录逻辑");
//        //1.根据用户名去数据库查询，如果不存在则抛异常
//        TbUser user = userService.login(username);
//        if (user==null){
//            throw new UsernameNotFoundException("用户名不存在");
//        }
//        //如果用户存在，则比较密码（注册密码是加密的）如果成功则返回成功
//        String password = passwordEncoder.encode(user.getPassword());
//        return new User(username,password, AuthorityUtils.commaSeparatedStringToAuthorityList("admin,normal"));
//    }
//}
